Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy_reflect: Disambiguate type bounds in where clauses. #8761

Merged
merged 4 commits into from
Jun 5, 2023
Merged

bevy_reflect: Disambiguate type bounds in where clauses. #8761

merged 4 commits into from
Jun 5, 2023

Conversation

Themayu
Copy link
Contributor

@Themayu Themayu commented Jun 5, 2023

Objective

It was accidentally found that rustc is unable to parse certain constructs in where clauses properly. bevy_reflect::Reflect's habit of copying and pasting the field types in a type's definition to its where clauses made it very easy to accidentally run into this behaviour - particularly with the construct

where
    for<'a> fn(&'a T) -> &'a T: Trait1 + Trait2

which was incorrectly parsed as

where
    for<'a> (fn(&'a T) -> &'a T: Trait1 + Trait2)
            ^                                   ^ incorrect syntax grouping

instead of

where
    (for<'a> fn(&'a T) -> &'a T): Trait1 + Trait2
    ^                          ^ correct syntax grouping

Fixes #8759

Solution

This commit fixes the issue by inserting explicit parentheses to disambiguate types from their bound lists.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2023

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Reflection Runtime information about types labels Jun 5, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a simple test here to prevent regressions :) I like the change itself though.

@Themayu
Copy link
Contributor Author

Themayu commented Jun 5, 2023

How would I go about doing that? I've never made tests for proc-macro output before.

EDIT: Question answered on Discord

Add this in a test 🙂 You don't need an assert or anything: it just needs to compile

It was accidentally found that rustc is unable to parse certain
constructs in `where` clauses properly. bevy_reflect::Reflect's habit
of copying and pasting the types in a struct's definition to its where
clauses made it very easy to accidentally run into this behaviour -
particularly with the construct
    for<'a> fn(&'a T) -> &'a T: Trait1 + Trait2

which was incorrectly parsed as
    for<'a> (fn(&'a T) -> &'a T: Trait1 + Trait2)

instead of
    (for<'a> fn(&'a T) -> &'a T): Trait1 + Trait2

This commit fixes the issue by inserting explicit parentheses to
disambiguate types from their bound lists.
@Themayu
Copy link
Contributor Author

Themayu commented Jun 5, 2023

Fixed a merge conflict that occurred due to unfortunate timing between my PR and another one.

Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just one comment

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 5, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 5, 2023
Merged via the queue into bevyengine:main with commit 1e97c79 Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Reflect derive macro expansion causes syntax ambiguity with Higher-Kinded Types.
3 participants